package demo.practice.leetcode_eveyday;

public class P7 {

    public static void main(String[] args) {
        //P7 p7 = new P7();
        //p7.reverse(-123);

        // System.out.println((1<<31) -1);

        System.out.println(String.format("%s %s",Integer.toBinaryString(Integer.MAX_VALUE),Integer.MAX_VALUE));
        System.out.println(String.format("%s %s",Integer.toBinaryString(Integer.MIN_VALUE),Integer.MIN_VALUE));
        System.out.println(String.format("%s %s",Integer.toBinaryString(Integer.MIN_VALUE-1),Integer.MIN_VALUE-1));
        System.out.println(String.format("%s %s",Integer.toBinaryString(Integer.MAX_VALUE+1),Integer.MAX_VALUE+1));
        System.out.println(String.format("%s %s",Integer.toBinaryString(Integer.MIN_VALUE+1),Integer.MIN_VALUE+1));




    }

    public int reverse(int x) {

        int out = 0;
        while (x != 0) {
            int y = x % 10;
            x = x / 10;

            //if(  out+y/10 > ((1 << 31) - 1)/10   )
            if (out + y / 10 > (Integer.MAX_VALUE) / 10)
                return 0;

            if (out + y / 10 < (Integer.MIN_VALUE) / 10)
                return 0;

            out = out * 10 + y;
            System.out.println(String.format("%s %s %s", x, y, out));
        }
        return out;
    }
}
